require 'parser/SymFunction.rb'

class ZeroesFunction < SymFunction
    
  # Constructor of the class
     def initialize
        @name = 'zeroes'
        @type = 'mat'
        @param_types = ['num', 'num']
    end

    # Function to get the type for the signature specified by 'params'
    # === Parameters
    # * params -> Signature of the function
    # === Return value
    # Type of the return value of the function acording to the specified signature
     def type params
      compare_types = []

      # Parameters are already checked, here we compare types
      for param in params
        compare_types.push param.type
      end

      if ['num'] == compare_types
        return 'vec'
      end
      if ['num', 'num'] == compare_types
        return 'mat'
      end
        raise "Las firmas aceptadas por la función zerose son: (num) y (num, num)" +
              " pero se encontró #{compare_types.to_s}"
    end

    # Executes de function contained in 'self'
    # === Parameters
    # * params -> True value of the parameters that the function will be evaluated with
    # * func_table -> Symbol table of the declared functions
    # === Return value
    # nil if executed with success or an error message
     def execute params, func_table
      if 1 == params.length
        if params[0] < 1
          return "Tratando vector de ceros con longitud menor a 1 '#{params[0]}'"
        end
        v = []
        for i in (0..params[0]-1)
          v.push(0)
        end
        @returned = Vector.new v
        @returned.type = 'vec_fil'
      else
        if params[0] < 1
          return "Tratando de crear matriz de ceros con altura menor a 1 '#{params[0]}'"
        end
        if params[1] < 1
          return "Tratando de crear matriz de ceros con ancho menor a 1 '#{params[0]}'"
        end
        lvec = []
        for i in (0..params[0]-1)
          v = []
          for i in (0..params[1]-1)
            v.push(0)
          end
          vec = Vector.new v
          lvec.push(vec)
        end
        @returned = Matrix.new lvec
      end
      nil
    end
end
